package blocksim.hash;

import java.security.NoSuchAlgorithmException;

import org.bdwyer.fingerprint.RabinFingerprintLong;
import org.bdwyer.polynomial.Polynomial;

/**
 * Rabin without reusing previous hash calculations.
 * 
 * @see also {@link RabinHashStrategy}
 * 
 * @author marcus
 */
public class NotWindowedRabinHashStrategy extends AbstractBufferedHashStrategy {

  public static final String STRATEGY_ID = "NotWindowedRabin";

  public static final int POLYNOMIAL_SIZE = 32;

  private RabinFingerprintLong rabin;

  public NotWindowedRabinHashStrategy(int windowSize) throws NoSuchAlgorithmException {
    super(windowSize);
    rabin = new RabinFingerprintLong(Polynomial.createIrreducible(POLYNOMIAL_SIZE));
  }

  @Override
  public byte[] hash() {
    rabin.pushBytes(data.array());
    return rabin.getFingerprint().toBigInteger().toByteArray();
  }

  @Override
  public String getName() {
    return STRATEGY_ID;
  }
}
